﻿using System.Data.Entity;
using System.Data.Entity.Infrastructure;

namespace MVCTask.Models
{
    public class TaskContext : DbContext
    {
        // You can add custom code to this file. Changes will not be overwritten.
        // 
        // If you want Entity Framework to drop and regenerate your database
        // automatically whenever you change your model schema, add the following
        // code to the Application_Start method in your Global.asax file.
        // Note: this will destroy and re-create your database with every model change.
        // 


        public DbSet<Task> Tasks { get; set; }

        public DbSet<Status> Status { get; set; }

        public DbSet<Category> Categories { get; set; }

        public class Initializer : DropCreateDatabaseIfModelChanges<TaskContext>
        {
            protected override void Seed(TaskContext context)
            {
                //Add sample status
                var _new = new Status { Description = "New" };
                var _completed = new Status { Description = "Completed" };
                foreach (var item in new[] { _new, _completed })
                {
                    context.Status.Add(item);
                }

                //Add sample categories
                var _blog = new Category { Description = "Blog" };
                var _faculty = new Category { Description = "Faculty" };
                foreach (var item in new[] { _blog, _faculty })
                {
                    context.Categories.Add(item);
                }

                //Add sample Tasks
                var items = new[]{
                    new Task{Description = "Add sample data", Details="Generate sample data for working in the blog", Status = _completed, Category = _blog},
                    new Task{Description = "Study Networking", Details="Read HTTP Headers", Status = _new, Category = _faculty},
                    new Task{Description = "Prepare MVC Talk", Details="Talk about scaffolding and all that", Status = _completed, Category = _blog},
                    new Task{Description = "IE9 Pinned Sites", Details="Create a Post about Pinned Sites", Status = _new, Category = _faculty}
                };

                foreach (var item in items)
                {
                    context.Tasks.Add(item);
                }
            }
        }

    }
}
